#!/bin/bash

# NC: downloaded from http://www.cs.cmu.edu/~joshuad/pdfrescale (Joshua Dunfield)
# NC: 1.2 was the right scale for my usage!

# Based on a batch file by Maverick Woo
#
# Usage:
#       pdfrescale path-stem scale-factor
#
# Example:
#       pdfrescale sillyLNCSpaper 1.2
# produces
#       sillyLNCSpaper-1.2.pdf

# NC: Started getting weird error:
#
# NC: Not writing to <some file>.aux (openout_any = p).
#
# NC: Fix:
# NC: http://email.esm.psu.edu/pipermail/macosx-tex/2006-February/020580.html
export openout_any=r

jobname=$1
if [ ! -f $jobname.pdf ]; then
  echo "Input file $jobname.pdf not found"
  exit 1
fi
scale=$2
if [ "$scale" == "" ]; then
  echo scale not specified, using default: 1.2
  scale=1.2
fi
tmp=`tempfile|sed -e 's/\./_/g'`.pdf

cp $1.pdf $tmp
pdflatex \
   -jobname="$jobname-$scale" \
   '\documentclass[twoside]{article}\usepackage{pdfpages}\begin{document}\includepdf[pages=-,scale='"$scale"']{'"$tmp"'}\end{document}\batchmode' \
   > /dev/null
\rm -f $tmp
\rm $jobname-$scale.aux $jobname-$scale.log
